require('./PageFillinfo.styl');
import { Control } from 'react-keeper'

const { TextField, Group, Button } = SaltUI;
const ui = require('clientConfig/util/jsapi/ui')
class Fillinfo extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            name: '',
            nickname: this.props.nickname
        };
    }
    handleTextChange(name, newValue) {
        this.setState({
            [name]: newValue
        });
    }
    handleClick() {
        let id = this.props.params.id;
        let type = this.props.params.type || Control.state.type;
        if (type == '1') {
            Control.go('/home', { id, content: this.state.name })
        } else if (type == '0') {
            Control.go('/bind/modify/fill', { id, content: this.state.name })
        }
    }
    render() {
        let t = this;
        return (
            <div className="fillinfo">
                <Group.Head className='tFS12 tLH2 tPT16'></Group.Head>
                <Group.List >
                    <TextField
                        label=""
                        placeholder=""
                        value={t.state.name}
                        onChange={t.handleTextChange.bind(t, 'name')}
                    />
                </Group.List>
                {(window.isBp || DingTalkPC.ua.isDesktop) && <Button className="btn" onClick={this.handleClick.bind(this)}>完成</Button>}
            </div>
        );
    }

    componentWillMount() {
        ui.setLeft({ control: true, text: '返回' }, (isSuccessed, result) => {
            // if (isSuccessed) {
            //     Control.go(-1)
            // }
            if (isSuccessed) {
                let id = this.props.params.id;
                let type = this.props.params.type || Control.state.type;
                console.log(Control)
                if (type == '1') {
                    Control.go('/home', { id, content: this.state.name })
                } else if (type == '0') {
                    Control.go('/bind/modify/fill', { id, content: this.state.name })
                }
            }
        })
    }

    componentDidMount() {
        ui.setNavigationRight({ text: '完成', control: true, show: true }, (isSuccessed, result) => {
            if (isSuccessed) {
                let id = this.props.params.id;
                let type = this.props.params.type || Control.state.type;
                console.log(Control)
                if (type == '1') {
                    // alert(JSON.stringify({ id, content: this.state.name }))
                    Control.go('/home', { id, content: this.state.name })
                } else if (type == '0') {
                    Control.go('/bind/modify/fill', { id, content: this.state.name })
                }
            }
        })
    }

    componentWillReceiveProps(nextProps) {
    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {
    }

    componentWillUnmount() {

    }
}

module.exports = Fillinfo;
